home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / tools / profiler / msprof / profprt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-11  |  2.2 KB  |  110 lines

  1. /*
  2.  * Print an analysis of the profiler results.
  3.  *
  4.  * (C) Copyright 1988, 1989 Diomidis D. Spinellis. All rights reserved.
  5.  * See the file profprt.c for distribution details.
  6.  * 
  7.  * The code contained herein is not optimal. It is given as a substitute
  8.  * for a ten line awk script that had the same functionality.
  9.  *
  10.  * $Header: PROFPRT.C^v 1.1 88/11/20 17:36:12 dds Rel $
  11.  *
  12.  * $Log:    PROFPRT.C^v $
  13.  * Revision 1.1  88/11/20  17:36:12  dds
  14.  * Initial revision
  15.  * 
  16.  */
  17.  
  18. #include <stddef.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21.  
  22.  
  23. /* Profiler output maximum line length */
  24. #define LINELEN 129
  25.  
  26. /* Linker output maximum symbol length */
  27. #define STRLEN    65
  28.  
  29. char *Argv0 ;
  30.  
  31. static char rcsid[] = "$Header: PROFPRT.C^v 1.1 88/11/20 17:36:12 dds Rel $" ;
  32.  
  33. static void usage(void) ;
  34.  
  35.  
  36. static void
  37. usage()
  38. {
  39.     fprintf(stderr, "Usage : %s [-h] [file]", Argv0);
  40.     exit(1);
  41. }
  42.  
  43. void
  44. main(int argc, char *argv[])
  45. {
  46.     FILE           *f;
  47.     long            t, total = 0, max = -1;
  48.     static char     line[LINELEN], str[STRLEN];
  49.     char           *fname = "prof.out";
  50.     int             histo = 0, fname_given = 0;
  51.     register        i;
  52.  
  53.     Argv0 = argv[0];
  54.  
  55.     while (argc > 1)
  56.         switch (*argv[1]) {
  57.         case '-':
  58.             if (argv[1][1] == 'h') {
  59.                 histo++;
  60.                 argc--;
  61.                 argv++;
  62.             } else
  63.                 usage();
  64.             break;
  65.         default:
  66.             if (fname_given)
  67.                 usage();
  68.             else {
  69.                 fname_given++;
  70.                 fname = argv[1];
  71.                 argc--;
  72.                 argv++;
  73.             }
  74.             break;
  75.         }
  76.  
  77.     if ((f = fopen(fname, "r")) == NULL) {
  78.         perror(fname);
  79.         exit(1);
  80.     }
  81.     for (i = 1; fgets(line, LINELEN, f); i++) {
  82.         if (sscanf(line, " %*s %ld ", &t) != 1) {
  83.             fprintf(stderr, "%s : Error in reading %s(%d)\n", 
  84.                 Argv0, fname, i);
  85.             exit(1);
  86.         }
  87.         total += t;
  88.         if (t > max)
  89.             max = t;
  90.     }
  91.     if (total == 0) {
  92.         fprintf(stderr, "%s : No hits found\n", Argv0);
  93.         exit(1);
  94.     }
  95.     (void) rewind(f);
  96.     while (fgets(line, LINELEN, f)) {
  97.         (void) sscanf(line, " %s %ld ", str, &t);
  98.         if (t) {
  99.             printf("%-20s %5.2lf%% ", *str == '_' ? str + 1 : 
  100.                    str, (double) t / (double) total * 100.0);
  101.             if (histo)
  102.                 for (i = 0; i < (int) ((double) t / 
  103.                         (double) max * 50); i++)
  104.                     putchar('*');
  105.             putchar('\n');
  106.         }
  107.     }
  108.     exit(0);
  109. }
  110.